package com.xls.commonlibrary.db.test;

import android.util.Log;

import com.xls.commonlibrary.db.ObjectBoxUtil;

import java.util.List;

import io.objectbox.Box;

public class DBUtil {//    使用案例
    private static volatile DBUtil singleton = null;
    private String TAG = "DBUtil";

    private DBUtil() {
    }

    public static DBUtil getInstance() {
        if (singleton == null) {
            synchronized (DBUtil.class) {
                if (singleton == null) {
                    singleton = new DBUtil();
                }
            }
        }
        return singleton;
    }


    public void insert() {

        Box<DB> box = ObjectBoxUtil.getInstance().getBoxStore().boxFor(DB.class);
        box.put(new DB("1", "10000"));
        box.put(new DB("2", "20000"));
        box.put(new DB("3", "30000"));
        box.put(new DB("9", "90000"));


        // log
        List<DB> list = box.getAll();
        for (DB bean : list) {
            Log.i(TAG, "BD  = " + bean.toString());
        }
    }

}
